package com.binaryTree;

public class SymmetricTree0129_101 {

    //递归
    public boolean isSymmetric(TreeNode root) {
        return compareTree(root.left, root.right);
    }

    private boolean compareTree(TreeNode left, TreeNode right) {
        if(left == null && right !=null) return false;
        else if(left != null && right == null) return false;
        else if(left == null && right == null) return true;
        else if(left.val != right.val) return false;

        boolean outside = compareTree(left.left,right.right);
        boolean inside = compareTree(left.right,right.left);
        return outside && inside;
    }
}
